package leetcode_core.leetcode_1;

import java.util.Stack;

public class DailyTemperatures {
    public  int[] dailyTemperatures(int[] temperatures) {
        int[] ans = new int[temperatures.length];
        Stack<Integer> s = new Stack<Integer>();//注意要存储的是下标
        for(int i = temperatures.length-1;i>=0;i--){
            while(!s.isEmpty() && temperatures[i] >= temperatures[s.peek()]){
                s.pop();
            }
            ans[i] = s.isEmpty()?0:(s.peek()-i);
            s.push(i);
        }
        return ans;
    }
}
